\documentclass[a4paper]{article}
\usepackage[affil-it]{authblk}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{ctex}
\usepackage{listings}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{booktabs}

\usepackage{geometry}
\geometry{margin=1.5cm, vmargin={0pt,1cm}}
\setlength{\topmargin}{-0.5cm}
\setlength{\paperheight}{29.7cm}
\setlength{\textheight}{25.3cm}

\begin{document}
% =================================================
\title{Report}

\author{徐翊钧 3220101901
  \thanks{Electronic address: \texttt{3220101901@zju.deu.cn}}}
\affil{(Qiangji2201), Zhejiang University }

\maketitle

\ctexset{
    abstractname = {Abstract}
}

\begin{abstract}  
This document shows the results of exercises and analyze the math theory behind the phenomenons.   
\end{abstract}

% ============================================
\part{Exercises.}
% ============================================
\section{A.}

\begin{table}[h]
\centering
\caption{Maximum Error Changes}
\label{tab:error_changes}
\begin{tabular}{cccccc}
\toprule
N & $|6|$ & $|11|$ & $|21|$ & $|41|$ & $|81|$ \\
\midrule
error & 0.423482 & 0.0205306 & 0.00316894 & 0.000275356 & 1.609e-05 \\
\bottomrule
\end{tabular}
\end{table}

The result can be seen from below theorem:

\textbf{Theorem 3.12.} Denote by $X_{b} := \left(x_{i}\right)_{i=1}^{N}$ the sequence of breakpoints in (3.1) and suppose that a scalar function $f \in \mathcal{C}^{2}([a, b]) \cap \mathcal{C}^{4}([a, b] \setminus X_{b})$ is interpolated by a complete cubic spline or a cubic spline with specified second derivatives at its end points. Then we have

\[
\forall x \in [a, b], \forall j = 0, 1, 2,
\]

\[
\left| f^{(j)}(x) - s^{(j)}(x) \right| \leq c_{j} h^{4-j} \max_{\xi \in [a, b] \setminus X_{b}} \left| f^{(4)}(\xi) \right|, \quad (3.20)
\]

\[
\text{where } c_{0} = \frac{1}{16}, \, c_{1} = c_{2} = \frac{1}{2}, \text{ and } h = \max_{i=1}^{N-1} \left| x_{i+1} - x_{i} \right|.
\]

% ============================================
\section{C.}
plot as below

we can see the cubic spline is more smooth and accurate than the quadratic spline.(remark: the blue line is the original function, orange line is the spline)

\begin{figure}[htbp]\
    \centering
    \begin{minipage}[t]{0.4\textwidth}
        \centering
        \includegraphics[scale=0.2]{../figure/C_quadratic_plot.png}
        \caption{quadratic spline}
    \end{minipage}
    \begin{minipage}[t]{0.4\textwidth}
        \centering
        \includegraphics[scale=0.2]{../figure/C_cubic_plot.png}
        \caption{cubic spline}  
    \end{minipage}    
\end{figure}

% ============================================
\section{D.}
\begin{table}[h]
\centering
\caption{Error Comparison between C\_Error and Q\_Error}
\label{tab:error_comparison}
\begin{tabular}{ccc}
\toprule
Points & Cubic\_Error & Quadratic\_Error \\
\midrule
-3.5   & 0.0007   & 0.0000   \\
-3.0   & 0.0000   & 0.0014   \\
-0.5   & 0.0205   & 0.0000   \\
0.0    & 0.0000   & 0.1202   \\
0.5    & 0.0205   & 0.0000   \\
3.0    & 0.0000   & 0.0014   \\
3.5    & 0.0007   & 0.0000   \\
\bottomrule
\end{tabular}
\end{table}
Because computing on the computer there might be a roundoff error which might cause a machine error.
Seen from the error table and the figure in C, we know the cubic spline is more accurate.

% ============================================
\section{E.}
Bezier Curve is more smooth but if you change one part of the curve, the whole fiure would change. 
Bspline curve is easier to control and it is more stable.

We can use BSpline curve to draw the heart shape. The more points we have, the more accurate the heart shape is.(remark: the blue line use cumulated 
knots and the red line use equidistance knots)

\begin{figure}[htbp]
\begin{minipage}[t]{0.3\textwidth}
    \centering
    \includegraphics[scale=0.2]{../figure/heart_10.png}
    \caption{heart with 10 points}
\end{minipage}
\begin{minipage}[t]{0.3\textwidth}
    \centering
    \includegraphics[scale=0.2]{../figure/heart_40.png}
    \caption{heart with 40 points}
\end{minipage}
\begin{minipage}[t]{0.3\textwidth}
    \centering
    \includegraphics[scale=0.2]{../figure/heart_160.png}
    \caption{heart with 160 points}
\end{minipage}
\end{figure}

Also the figure of $r_2$ is shown below.(remark: the blue line is the original function, the red line use cumulated knots, the green line use equidistance knots)

We can notice that cumulative knots are more accurate than equidistance knots. 

\begin{figure}[htbp]
    \centering
    \includegraphics[scale=0.2]{../figure/E_r2.png}
    \caption{r2}
\end{figure} 

We can fit a ball curve with bspline and the result is well-fitted.

\begin{figure}[htbp]
    \begin{minipage}[t]{0.4\textwidth}
        \centering
        \includegraphics[scale=0.2]{../figure/E_r3.png}
        \caption{spline ball curve}
    \end{minipage}
    \begin{minipage}[t]{0.4\textwidth}
        \centering
        \includegraphics[scale=0.2]{../figure/E_standard_r3.png}
        \caption{original curve}
    \end{minipage}
\end{figure}

% ============================================
\section{F.}
The result is shown below and we can see the divided difference is the same as the result in the book.

\begin{figure}[htbp]
    \centering
    \includegraphics[scale=0.2]{../figure/F_1.png}
    \caption{plot for degree 1 basic function}
    \centering
    \includegraphics[scale=0.2]{../figure/F_2.png}
    \caption{plot for degree 2 basic function}
\end{figure}

% ============================================
\part{Addition.}

In this section we perform more test on the spline to check its accuracy and function.

First, we can interpalte linear function with both ppspline and bspline accurately:

\begin{figure}[htbp]
    \centering
    \includegraphics[scale=0.2]{../figure/Linear.png}
    \caption{linear interpolation}
\end{figure}

Second, we check the ppform and bform is the same for same boundary condition:

\begin{figure}[htbp]
    \centering
    \begin{minipage}[t]{0.3\textwidth}
        \includegraphics[scale=0.2]{../figure/natural.png}
        \caption{natural boundary condition}
    \end{minipage}
    \begin{minipage}[t]{0.3\textwidth}
        \includegraphics[scale=0.2]{../figure/periodic.png}
        \caption{periodic boundary condition}
    \end{minipage}
    \begin{minipage}[t]{0.3\textwidth}
        \includegraphics[scale=0.2]{../figure/complete.png}
        \caption{complete boundary condition}
    \end{minipage}
    \end{figure}

Third, we test the spline with 2 weird fucniton which are $\frac{10sinx}{x}$ and $\sin(\frac{1}{x})$ and the result is shown below:

\begin{figure}[htbp]
    \centering
    \includegraphics[scale=0.2]{../figure/test.png}
    \caption{sin(1/x)}
    \end{figure}

\begin{figure}[htbp]
    \centering
    \includegraphics[scale=0.2]{../figure/test2.png}
    \caption{10*sin(x)/x}
    \end{figure}

At last, we test the any degree Bsplines in high degree 5 and 7 to interpoalte the function $f(x) = exp(-x^2)$. 
We can notice the spline passes all the interpalte points but there is disturbance in the boundary since no boundary condition is set.

\begin{figure}[htbp]
    \centering
    \includegraphics[scale=0.2]{../figure/anydegree.png}
    \caption{any degree bspline}
    \end{figure}


\end{document}